<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateQuestionFeedback extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('question_feedback')) {
            Schema::create('question_feedback', function (Blueprint $table) {
                $table->id();
                $table->unsignedInteger('user_id')->default(0)->comment('反馈人ID');
                $table->string('user_name')->default('')->comment('反馈人姓名');
                $table->unsignedInteger('wo_id')->default(0)->comment('工单ID');
                $table->string('wo_number')->default('')->comment('工单编号');
                $table->unsignedInteger('project_id')->default(0)->comment('姓名ID');
                $table->string('project_number')->default('')->comment('项目编号');
                $table->string('order_number')->default('')->comment('订单号');
                $table->unsignedTinyInteger('checked')->default(0)->comment('是否验收');
                $table->unsignedTinyInteger('is_quality')->default(0)->comment('是否质量问题');
                $table->unsignedInteger('product_id')->default(0)->comment('设备ID');
                $table->string('product_name')->default('')->comment('设备名称');
                $table->string('product_number')->default('')->comment('设备编号');
                $table->string('product_date')->default('')->comment('出厂日期');
                $table->unsignedInteger('quantity')->default(0)->comment('异常数量');
                $table->string('production_base')->default('')->comment('生产基地');
                $table->string('question_level')->default('')->comment('问题等级');
                $table->string('question_type')->default('')->comment('问题归类');
                $table->string('question_type_detail')->default('')->comment('问题归类明细');
                $table->unsignedTinyInteger('bom_replace')->default(0)->comment('是否更换备件');
                $table->string('customer_name')->default('')->comment('大区经理ID');
                $table->unsignedInteger('manager_id')->default(0)->comment('大区经理ID');
                $table->string('manager_name')->default('')->comment('大区经理名字');
                $table->unsignedInteger('quantity_user_id')->default(0)->comment('品质工程师ID');
                $table->string('quantity_user_name')->default('')->comment('品质工程师名字');
                $table->text('description')->nullable()->comment('问题描述');
                $table->text('reason')->nullable()->comment('原因分析');
                $table->text('measure_temp')->nullable()->comment('临时措施');
                $table->text('suggestion_manager')->nullable()->comment('区域经理建议处理意见');
                $table->string('suggestion_manager_time')->default('')->comment('区域经理审核时间');
                $table->unsignedInteger('dept_id')->default(0)->comment('责任部门ID');
                $table->string('dept_name')->default('')->comment('责任部门名称');
                $table->unsignedInteger('charge_user_id')->default(0)->comment('责任人ID');
                $table->string('charge_user_name')->default('')->comment('责任人姓名');
                $table->text('improve')->nullable()->comment('改善措施');
                $table->text('measure_reason')->nullable()->comment('原因分析');
                $table->text('measure_temp_scene')->nullable()->comment('临时措施: 品质工程师填写');
                $table->string('quantity_update_time')->default('')->comment('品质工程师处理时间');
                $table->string('status')->default('')->comment('状态');
                $table->integer('create_time')->nullable();
                $table->integer('update_time')->nullable();
            });
        }

        if (!Schema::hasTable('question_feedback_image')) {
            Schema::create('question_feedback_image', function (Blueprint $table) {
                $table->id();
                $table->unsignedInteger('qf_id')->default(0)->comment('质量反馈ID');
                $table->string('image')->default('')->comment('图片路径');
                $table->integer('create_time')->nullable();
                $table->integer('update_time')->nullable();
            });
        }

        if (!Schema::hasTable('question_feedback_history')) {
            Schema::create('question_feedback_history', function (Blueprint $table) {
                $table->id();
                $table->unsignedInteger('qf_id')->default(0)->comment('质量反馈ID');
                $table->unsignedInteger('user_id')->default(0)->comment('操作人ID');
                $table->text('image')->nullable()->comment('备注信息');
                $table->string('status')->default('')->comment('状态');
                $table->integer('create_time')->nullable();
                $table->integer('update_time')->nullable();
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('question_feedback');
    }
}
